<template>
    <div class="edit-popup">
        <popup
            ref="popupRef"
            :title="popupTitle"
            :async="true"
            width="550px"
            :clickModalClose="true"
            @confirm="handleSubmit"
            @close="handleClose"
        >
            <el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
                <el-form-item label="编号" prop="id">
                    <el-input v-model="formData.id" placeholder="请输入编号" />
                </el-form-item>
                <el-form-item label="客户编号" prop="clientId">
                    <el-input v-model="formData.clientId" placeholder="请输入客户编号" />
                </el-form-item>
                <el-form-item label=" 注册时间" prop="registerTime">
                    <el-input v-model="formData.registerTime" placeholder="请输入 注册时间" />
                </el-form-item>
                <el-form-item label="注册资金" prop="registerMoney">
                    <el-input v-model="formData.registerMoney" placeholder="请输入注册资金" />
                </el-form-item>
                <el-form-item label="注册类型" prop="registerType">
                    <el-select
                        class="flex-1"
                        v-model="formData.registerType"
                        placeholder="请选择注册类型"
                    >
                        <el-option label="请选择字典生成" value="" />
                    </el-select>
                </el-form-item>
                <el-form-item label="单位网址" prop="unitWebsite">
                    <el-input v-model="formData.unitWebsite" placeholder="请输入单位网址" />
                </el-form-item>
                <el-form-item label="单位负责人名称" prop="headOfUnitName">
                    <el-input
                        v-model="formData.headOfUnitName"
                        placeholder="请输入单位负责人名称"
                    />
                </el-form-item>
                <el-form-item label="单位负责人性别" prop="headOfUnitSex">
                    <el-select
                        class="flex-1"
                        v-model="formData.headOfUnitSex"
                        placeholder="请选择单位负责人性别"
                    >
                        <el-option label="请选择字典生成" value="" />
                    </el-select>
                </el-form-item>
                <el-form-item label="单位负责人手机" prop="headOfUnitPhone">
                    <el-input
                        v-model="formData.headOfUnitPhone"
                        placeholder="请输入单位负责人手机"
                    />
                </el-form-item>
                <el-form-item label="单位负责人电话" prop="headOfUnitNumber">
                    <el-input
                        v-model="formData.headOfUnitNumber"
                        placeholder="请输入单位负责人电话"
                    />
                </el-form-item>
                <el-form-item label="单位负责人职务" prop="headOfUnitPost">
                    <el-input
                        v-model="formData.headOfUnitPost"
                        placeholder="请输入单位负责人职务"
                    />
                </el-form-item>
                <el-form-item label="单位负责人邮箱" prop="headOfUnitEmail">
                    <el-input
                        v-model="formData.headOfUnitEmail"
                        placeholder="请输入单位负责人邮箱"
                    />
                </el-form-item>
                <el-form-item label="公司主营产品（服务）" prop="mainProducts">
                    <el-input
                        v-model="formData.mainProducts"
                        placeholder="请输入公司主营产品（服务）"
                    />
                </el-form-item>
                <el-form-item label="主营业务所属技术领域" prop="mainBusinessBelongs">
                    <el-input
                        v-model="formData.mainBusinessBelongs"
                        placeholder="请输入主营业务所属技术领域"
                    />
                </el-form-item>
                <el-form-item label="上游产品" prop="upstreamProducts">
                    <el-input v-model="formData.upstreamProducts" placeholder="请输入上游产品" />
                </el-form-item>
                <el-form-item label="下游产品" prop="downstreamProducts">
                    <el-input v-model="formData.downstreamProducts" placeholder="请输入下游产品" />
                </el-form-item>
                <el-form-item label="规上企业入库备案" prop="isStorageForRecord">
                    <el-input
                        v-model="formData.isStorageForRecord"
                        placeholder="请输入规上企业入库备案"
                    />
                </el-form-item>
                <el-form-item label="研发费用加计扣除" prop="isAdditionalDeduction">
                    <el-input
                        v-model="formData.isAdditionalDeduction"
                        placeholder="请输入研发费用加计扣除"
                    />
                </el-form-item>
                <el-form-item
                    label="园区或基
地注册"
                    prop="isParkRegistration"
                >
                    <el-input
                        v-model="formData.isParkRegistration"
                        placeholder="请输入园区或基
地注册"
                    />
                </el-form-item>
                <el-form-item label="园区或基地名称" prop="parkRegistrationName">
                    <el-input
                        v-model="formData.parkRegistrationName"
                        placeholder="请输入园区或基地名称"
                    />
                </el-form-item>
                <el-form-item label="是否建有博士科研工作站" prop="isDoctoralResearchStation">
                    <el-input
                        v-model="formData.isDoctoralResearchStation"
                        placeholder="请输入是否建有博士科研工作站"
                    />
                </el-form-item>
                <el-form-item label="进站博士(生)" prop="doctorPitStop">
                    <el-input v-model="formData.doctorPitStop" placeholder="请输入进站博士(生)" />
                </el-form-item>
                <el-form-item label="设备固定资产总额（万元）" prop="totalEquipment">
                    <el-input
                        v-model="formData.totalEquipment"
                        placeholder="请输入设备固定资产总额（万元）"
                    />
                </el-form-item>
                <el-form-item
                    label="未来1-3年
计划新增生产设备投入总额（万元）"
                    prop="futureTotal"
                >
                    <el-input
                        v-model="formData.futureTotal"
                        placeholder="请输入未来1-3年
计划新增生产设备投入总额（万元）"
                    />
                </el-form-item>
                <el-form-item label="信息化软件投入金额" prop="amountOfInvestment">
                    <el-input
                        v-model="formData.amountOfInvestment"
                        placeholder="请输入信息化软件投入金额"
                    />
                </el-form-item>
                <el-form-item label="信息化软件投入具体" prop="ofInvestmentBeSpecific">
                    <el-input
                        v-model="formData.ofInvestmentBeSpecific"
                        placeholder="请输入信息化软件投入具体"
                    />
                </el-form-item>
                <el-form-item label="信息化软件投入其他" prop="ofInvestmentOthers">
                    <el-input
                        v-model="formData.ofInvestmentOthers"
                        placeholder="请输入信息化软件投入其他"
                    />
                </el-form-item>
                <el-form-item label="业务系统是否向云端迁移" prop="isCloudMigration">
                    <el-input
                        v-model="formData.isCloudMigration"
                        placeholder="请输入业务系统是否向云端迁移"
                    />
                </el-form-item>
                <el-form-item
                    label="是否拥有制造业与互联网试点示范项目"
                    prop="isDemonstrationProject"
                >
                    <el-input
                        v-model="formData.isDemonstrationProject"
                        placeholder="请输入是否拥有制造业与互联网试点示范项目"
                    />
                </el-form-item>
                <el-form-item label="土地建设" prop="constructionOfLand">
                    <el-input v-model="formData.constructionOfLand" placeholder="请输入土地建设" />
                </el-form-item>
                <el-form-item label="上市情况" prop="listingStatus">
                    <el-radio-group v-model="formData.listingStatus" placeholder="请选择上市情况">
                        <el-radio label="0">请选择字典生成</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="上市进程" prop="goToMarketProcess">
                    <el-input v-model="formData.goToMarketProcess" placeholder="请输入上市进程" />
                </el-form-item>
                <el-form-item label="拟上市地" prop="placeOfListing">
                    <el-input v-model="formData.placeOfListing" placeholder="请输入拟上市地" />
                </el-form-item>
                <el-form-item label="融资需求额" prop="amountOfFinancingNeed">
                    <el-input
                        v-model="formData.amountOfFinancingNeed"
                        placeholder="请输入融资需求额"
                    />
                </el-form-item>
                <el-form-item label="计划融资方式" prop="plannedFinancingMethod">
                    <el-input
                        v-model="formData.plannedFinancingMethod"
                        placeholder="请输入计划融资方式"
                    />
                </el-form-item>
                <el-form-item label="销售收入" prop="revenueFromSales">
                    <el-input v-model="formData.revenueFromSales" placeholder="请输入销售收入" />
                </el-form-item>
                <el-form-item label="总资产" prop="totalAssets">
                    <el-input v-model="formData.totalAssets" placeholder="请输入总资产" />
                </el-form-item>
                <el-form-item label="净资产" prop="netWorth">
                    <el-input v-model="formData.netWorth" placeholder="请输入净资产" />
                </el-form-item>
                <el-form-item label="净利润" prop="netProfit">
                    <el-input v-model="formData.netProfit" placeholder="请输入净利润" />
                </el-form-item>
                <el-form-item label="净利润率" prop="netProfitMargin">
                    <el-input v-model="formData.netProfitMargin" placeholder="请输入净利润率" />
                </el-form-item>
                <el-form-item label="总负债" prop="totalLiabilities">
                    <el-input v-model="formData.totalLiabilities" placeholder="请输入总负债" />
                </el-form-item>
                <el-form-item label="研发费用" prop="research andDevelopmentExpenses">
                    <el-input
                        v-model="formData.researchAndDevelopmentExpenses"
                        placeholder="请输入研发费用"
                    />
                </el-form-item>
                <el-form-item label="研发费用占比" prop="proportion">
                    <el-input v-model="formData.proportion" placeholder="请输入研发费用占比" />
                </el-form-item>
                <el-form-item label="纳税额" prop="amountOfTaxPaid">
                    <el-input v-model="formData.amountOfTaxPaid" placeholder="请输入纳税额" />
                </el-form-item>
                <el-form-item label="资产负债率" prop="assetLiabilityRatio">
                    <el-input
                        v-model="formData.assetLiabilityRatio"
                        placeholder="请输入资产负债率"
                    />
                </el-form-item>
                <el-form-item label="银行贷款" prop="bankLoan">
                    <el-input v-model="formData.bankLoan" placeholder="请输入银行贷款" />
                </el-form-item>
                <el-form-item label="出口额" prop="volumeOfExports">
                    <el-input v-model="formData.volumeOfExports" placeholder="请输入出口额" />
                </el-form-item>
                <el-form-item
                    label="职工总数
（上年月平均人数）"
                    prop="totalNumber"
                >
                    <el-input
                        v-model="formData.totalNumber"
                        placeholder="请输入职工总数
（上年月平均人数）"
                    />
                </el-form-item>
                <el-form-item label="社保" prop="socialSecurity">
                    <el-input v-model="formData.socialSecurity" placeholder="请输入社保" />
                </el-form-item>
                <el-form-item label="个税" prop="personalIncomeTax">
                    <el-input v-model="formData.personalIncomeTax" placeholder="请输入个税" />
                </el-form-item>
                <el-form-item label="直接从事研发人员数" prop="personnelNumber">
                    <el-input
                        v-model="formData.personnelNumber"
                        placeholder="请输入直接从事研发人员数"
                    />
                </el-form-item>
                <el-form-item label="博士" prop="phd">
                    <el-input v-model="formData.phd" placeholder="请输入博士" />
                </el-form-item>
                <el-form-item label="硕士" prop="master">
                    <el-input v-model="formData.master" placeholder="请输入硕士" />
                </el-form-item>
                <el-form-item label="博士（理工科）" prop="phdLg">
                    <el-input v-model="formData.phdLg" placeholder="请输入博士（理工科）" />
                </el-form-item>
                <el-form-item label="硕士（理工科）" prop="masterLg">
                    <el-input v-model="formData.masterLg" placeholder="请输入硕士（理工科）" />
                </el-form-item>
                <el-form-item label="本科" prop="undergraduate">
                    <el-input v-model="formData.undergraduate" placeholder="请输入本科" />
                </el-form-item>
                <el-form-item label="专科" prop="specialistDepartment">
                    <el-input v-model="formData.specialistDepartment" placeholder="请输入专科" />
                </el-form-item>
                <el-form-item label="本科（理工科）" prop="undergraduateLg">
                    <el-input
                        v-model="formData.undergraduateLg"
                        placeholder="请输入本科（理工科）"
                    />
                </el-form-item>
                <el-form-item label="专科（理工科）" prop="specialistDepartmentLg">
                    <el-input
                        v-model="formData.specialistDepartmentLg"
                        placeholder="请输入专科（理工科）"
                    />
                </el-form-item>
                <el-form-item label="高级职称" prop="seniorProfessionaTitle">
                    <el-input
                        v-model="formData.seniorProfessionaTitle"
                        placeholder="请输入高级职称"
                    />
                </el-form-item>
                <el-form-item label="中级职称" prop="intermediateProfessionalTitle">
                    <el-input
                        v-model="formData.intermediateProfessionalTitle"
                        placeholder="请输入中级职称"
                    />
                </el-form-item>
                <el-form-item label="初级职称" prop="juniorProfessionalTitle">
                    <el-input
                        v-model="formData.juniorProfessionalTitle"
                        placeholder="请输入初级职称"
                    />
                </el-form-item>
                <el-form-item label="留学归国" prop="returnFromStudyAbroad">
                    <el-input
                        v-model="formData.returnFromStudyAbroad"
                        placeholder="请输入留学归国"
                    />
                </el-form-item>
                <el-form-item label="产品名称" prop="productName">
                    <el-input v-model="formData.productName" placeholder="请输入产品名称" />
                </el-form-item>
                <el-form-item label="当年产值(万元)" prop="annualOutputValue">
                    <el-input
                        v-model="formData.annualOutputValue"
                        placeholder="请输入当年产值(万元)"
                    />
                </el-form-item>
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { detailEdit, detailAdd, detailDetail } from '@/api/detail'
import Popup from '@/components/popup/index.vue'
import feedback from '@/utils/feedback'
import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const popupTitle = computed(() => {
    return mode.value == 'edit' ? '编辑【请填写功能名称】' : '新增【请填写功能名称】'
})

const formData = reactive({
    id: '',
    clientId: '',
    registerTime: '',
    registerMoney: '',
    registerType: '',
    unitWebsite: '',
    headOfUnitName: '',
    headOfUnitSex: '',
    headOfUnitPhone: '',
    headOfUnitNumber: '',
    headOfUnitPost: '',
    headOfUnitEmail: '',
    mainProducts: '',
    mainBusinessBelongs: '',
    upstreamProducts: '',
    downstreamProducts: '',
    isStorageForRecord: '',
    isAdditionalDeduction: '',
    isParkRegistration: '',
    parkRegistrationName: '',
    isDoctoralResearchStation: '',
    doctorPitStop: '',
    totalEquipment: '',
    futureTotal: '',
    amountOfInvestment: '',
    ofInvestmentBeSpecific: '',
    ofInvestmentOthers: '',
    isCloudMigration: '',
    isDemonstrationProject: '',
    constructionOfLand: '',
    listingStatus: '',
    goToMarketProcess: '',
    placeOfListing: '',
    amountOfFinancingNeed: '',
    plannedFinancingMethod: '',
    revenueFromSales: '',
    totalAssets: '',
    netWorth: '',
    netProfit: '',
    netProfitMargin: '',
    totalLiabilities: '',
    researchAndDevelopmentExpenses: '',
    proportion: '',
    amountOfTaxPaid: '',
    assetLiabilityRatio: '',
    bankLoan: '',
    volumeOfExports: '',
    totalNumber: '',
    socialSecurity: '',
    personalIncomeTax: '',
    personnelNumber: '',
    phd: '',
    master: '',
    phdLg: '',
    masterLg: '',
    undergraduate: '',
    specialistDepartment: '',
    undergraduateLg: '',
    specialistDepartmentLg: '',
    seniorProfessionaTitle: '',
    intermediateProfessionalTitle: '',
    juniorProfessionalTitle: '',
    returnFromStudyAbroad: '',
    productName: '',
    annualOutputValue: ''
})

const formRules = {}

const handleSubmit = async () => {
    await formRef.value?.validate()
    const data: any = { ...formData }
    mode.value == 'edit' ? await detailEdit(data) : await detailAdd(data)
    popupRef.value?.close()
    feedback.msgSuccess('操作成功')
    emit('success')
}

const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

const setFormData = async (data: Record<string, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]
        }
    }
}

const getDetail = async (row: Record<string, any>) => {
    const data = await detailDetail({
        id: row.id
    })
    setFormData(data)
}

const handleClose = () => {
    emit('close')
}

defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
